<template>
	<div class="ts-form-table">
		<el-table :data="data" ref="table" :key="toggleIndex" width="400" border stripe
			:header-cell-style="{ 'color': '#000' }">
			<el-table-column type="index" width="50" fixed="left">
				<template #header>
					<el-button v-if="!disabled" type="primary" size="small" :icon="Plus" circle @click="rowAdd">
					</el-button>
				</template>
				<template #default="scope" v-if="!disabled">
					<div class="ts-form-table-handle">
						<span>{{ scope.$index + 1 }}</span>
						<el-button type="danger" size="small" :icon="Delete" plain circle
							@click="rowDel(scope.row, scope.$index)">
						</el-button>
					</div>
				</template>
			</el-table-column>
            <el-table-column label="关系" width="50">
                <template #default="scope">
                    {{ scope.$index == 0 ? '当' : (mode ? '且' : '或') }}
                </template>
            </el-table-column>
			<slot name="tableContent"></slot>
			<template #empty>
				{{ placeholder }}
			</template>
		</el-table>
	</div>
</template>
<script setup>
import { Plus, Delete, DCaret, Edit } from '@element-plus/icons-vue';

</script>

<script>
export default {
	props: {
		modelValue: { type: Array, default: () => [] },
		addTemplate: { type: Object, default: () => { } },
		expressTemplate: { type: Object, default: () => { } },
		placeholder: { type: String, default: "暂无数据" },
		disabled: { type: Boolean, default: false },
        mode:{ type: Boolean, default: false }
	},
	data() {
		return {
			data: [],
			toggleIndex: 0,
			type:'simple'
		}
	},
	mounted() {
		this.data = this.modelValue
		if (this.dragSort) {
			this.rowDrop()
		}
	},
	watch: {
		modelValue() {
			this.data = this.modelValue
		},
		data: {
			handler() {
				this.$emit('update:modelValue', this.data);
			},
			deep: true
		}
	},
	methods: {
		rowAdd() {
			let temp;
			temp = JSON.parse(JSON.stringify(this.addTemplate))
			this.data.push(temp)
		},
		rowDel(row, index) {
			this.data.splice(index, 1)
		},
	}
}
</script>

<style scoped>
.ts-form-table {
	width: 100%;
}

.ts-form-table .ts-form-table-handle {
	text-align: center;
}

.ts-form-table .ts-form-table-handle span {
	display: inline-block;
}

.ts-form-table .ts-form-table-handle button {
	display: none;
}

.ts-form-table .hover-row .ts-form-table-handle span {
	display: none;
}

.ts-form-table .hover-row .ts-form-table-handle button {
	display: inline-block;
}
</style>
